package com.ruoyi.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ProductThreadPoolConfig {

    @Bean(name = "itemThreadPoolExecutor")
    public ThreadPoolExecutor itemThreadPoolExecutor(ItemThreadPoolProperties itemThreadPoolProperties){

        return new ThreadPoolExecutor(
                //java查吗
                itemThreadPoolProperties.getCorePoolSize(),
                itemThreadPoolProperties.getMaxPoolSize(),
                itemThreadPoolProperties.getKeepAliveTime(),
                TimeUnit.MINUTES,
                new LinkedBlockingDeque<>(itemThreadPoolProperties.getQueueLength()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    @Bean
    public ThreadPoolExecutor imgUploadThreadPoolExcuter(){

        return new ThreadPoolExecutor(
                //java查吗
                6,
                20,
                5,
                TimeUnit.MINUTES,
                new LinkedBlockingDeque<>(300),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
